package com.adminpcBo;


import java.util.ArrayList;
import java.util.List;

import javax.faces.component.html.HtmlDataTable;
import javax.faces.component.html.HtmlInputHidden;

import com.adminpcDao.*;
import com.adminpcMod.*;

public class FileBo {
	private FileDao fileBo = new FileDao();
	private HtmlDataTable dataTab;
    private File dataItem = new  File();
    private HtmlInputHidden dataItemId = new HtmlInputHidden();
	private long identiFileBo;
	private String nameFileBo;
	private String pathFileBo;
	private String contentFileBo;
	private List<File> filebo;
	private File updatfile;
	private List<File> selectedDataList;
	private ClientBo client = new ClientBo();
	private UserBo userbo = new UserBo();

	 // Actions -----------------------------------------------------------------------------------
	public String getuserFi(){
		
	  
  	  File dataItem = (File) dataTab.getRowData();
  	  client.excute(dataItem.getComputer().getIpadresseComputer(),dataItem.getNameFile(),dataItem.getPathFile()
  			  ,dataItem.getContentFile());
	       return dataItem.getNameFile();
	}
	public String Update() {
       // Get selected MyData item to be edited.
     File updatfile = (File) dataTab.getRowData();
     updatfile.setEditable(true);
     return "null";
   }
   
   public void Save() {  
	 File updatfile = (File) dataTab.getRowData();  
	 fileBo.updatefile(updatfile); 
	 updatfile.setEditable(false);
	 
   }

   
   public void DeletDataItem() {
	        // Get selected MyData item to be edited.
	         //int lenght = (int) dataTab.getRowCount();
	   filebo = userbo.file;
	   selectedDataList = new ArrayList<File>(); 
       for (File dataItem : filebo){
           if (dataItem.isDelet()) {
        	   System.out.println(dataTab.getRowIndex());
        	   System.out.println(dataItem.getIdentiFile());
        	   fileBo.deleteFile(dataItem.getIdentiFile());
               filebo.remove(dataItem);
           }
        }
       userbo.setFile(filebo);
   }

   public List<File> getSelectedDataList() {
       return selectedDataList;
   }
   
   
   
   // Getters -----------------------------------------------------------------------------------

   public HtmlDataTable getDataTab() {
       return dataTab;
   }

   public File getDataItem() {
       return dataItem;
   }

   public HtmlInputHidden getDataItemId() {
       return dataItemId;
   }
// Setters -----------------------------------------------------------------------------------

   public void setDataTab(HtmlDataTable dataTab) {
       this.dataTab = dataTab;
   }

   public void setDataItem(File dataItem) {
       this.dataItem = dataItem;
   }

   public void setDataItemId(HtmlInputHidden dataItemId) {
       this.dataItemId = dataItemId;

   }
/////////////////////
	public long getIdentiFileBo() {
		return identiFileBo;
	}
	public void setIdentiFileBo(long identiFileBo) {
		this.identiFileBo = identiFileBo;
	}
	public String getNameFileBo() {
		return nameFileBo;
	}
	public void setNameFileBo(String nameFileBo) {
		this.nameFileBo = nameFileBo;
	}
	public String getPathFileBo() {
		return pathFileBo;
	}
	public void setPathFileBo(String pathFileBo) {
		this.pathFileBo = pathFileBo;
	}

	public void setContentFileBo(String contentFileBo) {
		this.contentFileBo = contentFileBo;
	}
	public List<File> getFilebo() {
		return filebo;
	}
	public void setFilebo(List<File> filebo) {
		this.filebo = filebo;
	}
	
}
